package com.tierstall.server.model;

import java.io.Serializable;
import java.util.UUID;

import com.tierstall.shared.UserDTO;
import com.tierstall.shared.UserType;

@SuppressWarnings("serial")
public class User implements Serializable {

	private UUID id;
	private String username;
	private String password;
	private String firstname;
	private String lastname;
	private String department;
	private String email;
	private UserType permission;

	public User() {
	}

	public User(UUID id) {
		this.id = id;
	}

	public User(UserDTO user) {
		if (user.getId() != null && !user.getId().equals("")) {
			id = UUID.fromString(user.getId());
			System.out.println("---------> from string: "+ user.getId() + "---->" + id.toString());
		} else
			id = null;
		setData(id, user.getUsername(), user.getPassword(),
				user.getPermission(), user.getFirstname(), user.getLastname(),
				user.getEmail(), user.getDepartment());

	}

	public User(UUID id, String username, String password, UserType permission,
			String firstname, String lastname, String email, String department) {
		setData(id, username, password, permission, firstname, lastname, email,
				department);
	}

	private void setData(UUID id, String username, String password,
			UserType permission, String firstname, String lastname, String email,
			String department) {
		this.id = id;
		this.username = username;
		this.password = password;
		this.permission = permission;
		this.firstname = firstname;
		this.lastname = lastname;
		this.email = email;
		this.department = department;
	}

	// public UserUUID convertToUserUUID() {
	// UserUUID user = new UserUUID();
	// user.setUsername(getUsername());
	// user.setFirstname(getFirstname());
	// user.setLastname(getLastname());
	// //user.setId(UUID.fromString(useruuid.getId()));
	// user.setPassword(getPassword());
	// user.setPermission(getPermission());
	// user.setDepartment(getDepartment());
	// return user;
	// }

	public UUID getId() {
		return id;
	}

	public void setId(UUID id) {
		this.id = id;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public UserType getPermission() {
		return permission;
	}

	public void setPermission(UserType permission) {
		this.permission = permission;
	}

	public String getFirstname() {
		return firstname;
	}

	public void setFirstname(String firstname) {
		this.firstname = firstname;
	}

	public String getLastname() {
		return lastname;
	}

	public void setLastname(String lastname) {
		this.lastname = lastname;
	}

	public String getDepartment() {
		return department;
	}

	public void setDepartment(String department) {
		this.department = department;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}
}
